package com.quzhi.sys.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.quzhi.sys.entity.Warehouse;
import com.quzhi.sys.mapper.WarehouseMapper;
import com.quzhi.sys.service.IWarehouseService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author Xibing
 * @since 2024-07-23
 */
@Service
public class WarehouseServiceImpl extends ServiceImpl<WarehouseMapper, Warehouse> implements IWarehouseService {

    /**
     * 获取所有仓库名称
     *
     * @return
     */
    @Override
    public List<Map<String, String>> getAllWarehouseNameAndId() {
        // 查询所有仓库
        LambdaQueryWrapper<Warehouse> wrapper = new LambdaQueryWrapper<>();
        List<Warehouse> warehouseList = this.baseMapper.selectList(wrapper);
        List<Map<String, String>> AllWarehouseNameAndId = new ArrayList<>();
        for (Warehouse warehouse : warehouseList) {
            Map<String, String> data = new HashMap<>();

            String warehouseName = warehouse.getWarehouseName();
            String warehouseId = warehouse.getId();

            data.put("warehouseId", warehouseId);
            data.put("warehouseName", warehouseName);

            AllWarehouseNameAndId.add(data);
        }
        return AllWarehouseNameAndId;
    }
}
